﻿using Autofac.Core;
using IntelligentAgriculture.Contracts.Interface;
using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.WebAPI.Application.Command.StartCommand;
using MediatR;

namespace IntelligentAgriculture.WebAPI.Application.CommandHandler.StartCommandHandler
{
    /// <summary>
    /// 期初修改CommandHandler
    /// </summary>
    public class StartUpdateCommandHandler : IRequestHandler<StartUpdateCommand, Results<int>>
    {
        private readonly IStartService _startService;

        public StartUpdateCommandHandler(IStartService startService)
        {
            _startService = startService;
        }

        public async Task<Results<int>> Handle(StartUpdateCommand request, CancellationToken cancellationToken)
        {
            var entity = new Start()
            {
                StartId = request.StartId,
                ColumnManagementId = request.ColumnManagementId,
                DocumentNumber = request.DocumentNumber,
                ReplantingDate=request.ReplantingDate,
                OpeningDate=request.OpeningDate,
            
                EarTag = request.EarTag,
                Isdel = false,
                OnlyNumber = request.OnlyNumber,
                RidgepoleId = request.RidgepoleId,
                Stage = request.Stage,
                Type = request.Type,
                Weight = request.Weight,
                Remark = request.Remark,
                CreateName="Admin",
                CreateDate= request.CreateDate,
                UpdateDate = DateTime.Now,
                UpdateName = "张三",

            };
            var list = await _startService.UpdateStartAsync(entity);
            // 返回结果
            return Results<int>.DataResult(list);
        }
    }
}
